package org.apache.commons.pool2;

import java.io.Closeable;
import java.util.NoSuchElementException;

/**
 * 类的描述
 *
 * @author ztkool
 * @version v
 */
public interface ObjectPool<T> extends Closeable {

    /**
     * 从 池 中获取对象
     *
     * @return
     * @throws Exception
     * @throws NoSuchElementException
     * @throws IllegalStateException
     */
    T borrowObject() throws Exception, NoSuchElementException, IllegalStateException;

    /**
     * 将对象返回给 池
     *
     * @param obj
     * @throws Exception
     */
    void returnObject(T obj) throws Exception;

    /**
     * 使 池 中的对象无效
     *
     * @param obj
     * @throws Exception
     */
    void invalidateObject(T obj) throws Exception;

    /**
     * 将对象放入 空闲池
     * 用于预加载空闲池对象
     *
     * @throws Exception
     * @throws IllegalStateException
     * @throws UnsupportedOperationException
     */
    void addObject() throws Exception, IllegalStateException, UnsupportedOperationException;

    /**
     * 获取空闲池对象数量
     *
     * @return
     */
    int getNumIdle();

    /**
     * 返回活跃池对象数量
     *
     * @return
     */
    int getNumActive();

    /**
     * 清空池中空闲对象
     *
     * @throws Exception
     * @throws UnsupportedOperationException
     */
    void clear() throws Exception, UnsupportedOperationException;

    /**
     * 关闭池
     */
    @Override
    void close();
}
